package com.yue.procress;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yue.bean.json.Foo;

import java.io.IOException;

/**
 * 功能描述: TODO <br/>
 * 创建时间: 2016/10/8<br/>
 *
 * @author QiuYang
 */
public class ParserJson {
    public static void main(String[] args) {
        String json = "[{\"foo\":\"bar\"},{\"foo\":\"biz\"}]";

        JsonFactory jsonFactory = new JsonFactory();
        try {
            JsonParser jsonParser = jsonFactory.createParser(json);
            jsonParser.nextToken();

            ObjectMapper mapper = new ObjectMapper();
            while (jsonParser.nextToken() == JsonToken.START_OBJECT){
                Foo foo = mapper.readValue(jsonParser, Foo.class);
                System.out.println(foo.getFoo());
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
